package org.jeecg.modules.car.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.SsoUtil;
import org.jeecg.common.util.StringUtils;
import org.jeecg.entity.car.CarParkingRecord;
import org.jeecg.modules.car.mapper.CarInfoMapper;
import org.jeecg.modules.car.mapper.CarParkingRecordMapper;
import org.jeecg.modules.car.service.ICarParkingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 车场进出记录
 * @Author: jeecg-boot
 * @Date:   2020-09-27
 * @Version: V1.0
 */
@Service
public class CarParkingRecordServiceImpl extends ServiceImpl<CarParkingRecordMapper, CarParkingRecord> implements ICarParkingRecordService {

    @Autowired
    private CarParkingRecordMapper carParkingRecordMapper;
    @Autowired
    private CarInfoMapper carInfoMapper;

    @Override
    public Integer addOrUpdate(CarParkingRecord carParkingRecord) {
       return carParkingRecordMapper.addOrUpate(carParkingRecord);
    }

    @Override
    public CarParkingRecord getParkingRecordByCarNo(String carNo) {
        return carParkingRecordMapper.getParkingRecordByCarNo(carNo);
    }

    @Override
    public List<CarParkingRecord> findPage(Page<CarParkingRecord> page, CarParkingRecord carParkingRecord) {
        carParkingRecord.setTenantId(SsoUtil.getLoginUser().getTenantId());
        if (StringUtils.isNotBlank(carParkingRecord.getCarPortNum())){
            List<String> ids = carInfoMapper.getCarIdByCarPortNum(carParkingRecord.getCarPortNum());
            if (ids != null && ids.size() > 0){
                carParkingRecord.setCarIds(ids);
            }
        }
        return carParkingRecordMapper.findPage(page,carParkingRecord);
    }

    @Override
    public CarParkingRecord getByRecordId(String recordId, Integer isExit) {
        return carParkingRecordMapper.getByRecordId(recordId,isExit);
    }

    @Override
    public List<CarParkingRecord> getByCarNosAndParkId(String tenantId, List<String> carNos, String parkId){
        return carParkingRecordMapper.getByCarNosAndParkId(tenantId, carNos, parkId);
    }

    @Override
    public List<CarParkingRecord> selectNotSyncShParking(String parkId,String resendDate) {
        return carParkingRecordMapper.selectNotSyncShParking(parkId,resendDate);
    }

    @Override
    public Integer getIsExitByPlate(String carNo) {
        return carParkingRecordMapper.getIsExitByPlate(carNo);
    }
}
